package nl.saxion.security.gui.elements;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;

import nl.saxion.security.config.Config;
import nl.saxion.security.event.Event;

import nl.saxion.security.gui.elements.ConsoleReader;

import com.adamtaft.eb.EventBusService;
import com.adamtaft.eb.EventHandler;
import com.google.inject.Inject;
import com.google.inject.name.Named;

public class SyncListPanel extends AbstractSyncListPanel {

	private static final long serialVersionUID = 2011628665388677088L;

	private JList list;
	
	private DefaultListModel files;
	
	private Config config;
	
	@Inject
	public SyncListPanel(@Named("DefaultConfig") Config c) {
		super();
		config = c;
		configure();
		
		EventBusService.subscribe(this);
	}
	
	protected void configure()
	{
		setLayout(new BorderLayout());
		configureList();
	}
	
	private void configureList()
	{
		String fontFamily = config.getAsString(Config.KEY_GUI_FONT_FAMILY,"Helvetica");
		int fontSize = config.getAsInt(Config.KEY_GUI_FONT_SIZE,12);
		files = new DefaultListModel();
		//files.add(0, "Er zijn geen bestanden geselecteerd voor synchronisatie.");
		list = new JList(files);
		list.setFont(new Font(fontFamily, Font.PLAIN, fontSize));
		list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
	    list.setLayoutOrientation(JList.VERTICAL_WRAP);
		
		JScrollPane scrollPane = new JScrollPane(list);
		scrollPane.setPreferredSize(new Dimension(400, 155));
		
		add(scrollPane);
		ConsoleReader cr = new ConsoleReader(files);
		cr.start();
	}
	
	@EventHandler
	public void eventHandler(Event event)
	{
		
		
	}
	
	public DefaultListModel getDefaultListModel() {
		return files;
	}

}
